/*~~~~~~~~~~~~~~~~~~~~~~
[Bot IRC]
Auteur: Thaeron
Projet: NewSyndrome
Version: 1.6.8
Licence: GPL

Copyright (C) 2004 - 2010 Thaeron

This program is free software; you can redistribute it and/or 
modify it under the terms of the GNU General Public License as 
published by the Free Software Foundation; either version 2 of the 
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
General Public License for more details.

You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 
USA
~~~~~~~~~~~~~~~~~~~~~~*/

#ifndef _NS_MODULE_HEADER_
#define _NS_MODULE_HEADER_

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

#define NS_VERSION "NewSyndrome 1.6.8"    /* MAJOR = 1 , MINOR = 6, SUB_MINOR = 8 */
#define NS_VERSION_ID 10608		/* MAJOR*10000 + MINOR*100 + SUB_MINOR */

#define byte char
#define bot_add_timeout_int_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,sizeof(int))
#define bot_add_timeout_str_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,strlen(z)+1)
#define bot_add_timeout_char_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,1)
#define bot_add_timeout_byte_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,1)
#define bot_add_timeout_ptr_param_handler(x,y,z) bot_add_timeout_with_param_handler(x,y,z,0)


#ifdef ENABLE_NS_MALLOC
#undef malloc
#undef free
#undef calloc
#undef realloc
#undef strdup
#define malloc(x) ns_malloc(__FILE__,__LINE__,x)
#define free(x) ns_free(__FILE__,__LINE__,x)
#define calloc(x,y) ns_calloc(__FILE__,__LINE__,x,y)
#define realloc(x,y) ns_realloc(__FILE__,__LINE__,x,y)
#define strdup(x) ns_strdup(__FILE__,__LINE__,x)
#ifdef __cplusplus
extern "C" {
#endif
void *ns_calloc (const char *file, int line, size_t nmemb, size_t size);
void *ns_malloc (const char *file, int line, size_t size);
void ns_free (const char *file, int line, void *ptr);
void *ns_realloc (const char *file, int line, void *ptr, size_t size);
char *ns_strdup (const char *file, int line, const char *s);
#ifdef __cplusplus
}
#endif
#endif


#ifndef WIN32
	#ifdef NS_INTERNATIONALIZE
		#include <libintl.h>
		#include <locale.h>
		#define _(String) gettext(String)
	#else
		#define _(String) String
	#endif
#else
	#define _(String) String
#endif


enum
{ CLEAN, UNLOAD, LOAD, UNLINK, UPDATE, REHASH, REINIT };

enum
{ LOAD_OK, NO_MODULE, NO_IDENT, ALREADY_LOAD, UNLOAD_OK, ALREADY_UNLOAD, NO_CMD };

enum
{ BAD, GOOD };

enum
{ REMOVE_TIMEOUT, KEEP_TIMEOUT };

enum
{ CONF_DELETE_BY_KEY, CONF_DELETE_BY_VAL, CONF_UPDATE_VAL, CONF_ADD_KEY, CONF_COMMENT_LINE };

enum
{ FD_CHECK_RD = 0, FD_CHECK_WR, FD_CHECK_RDWR };

enum
{ REMOVE_FD_HANDLER, KEEP_FD_HANDLER };


typedef struct _func_list *ns_handler_t;
typedef struct _timeout_list *ns_timeout_t;
typedef struct _fd_list *ns_fd_t;

typedef struct _conf_bot conf_bot;
struct _conf_bot
{
	char *filename;
	char *nick;
	char *rn;
	char *ident;
	char *server;
	char *myip;
	char *root_path;
	char *bdd_path;
	char *charset_from;
	char *charset_to;
	char *nickserv_pass;
	char *server_pass;
	char *module_path;
	int port;
	int nbchan;
	char **channel;
	char car_cmd;
	byte af_default;
	int af_delay;
	int reco_delay;
	byte use_ssl;
};


typedef struct _msg msg;
struct _msg
{
	char **argu;
	int nbarg;
	char *sender;
	char *sender_nick;
	char *sender_ident;
	char *sender_host;
	char *cmd;
	char *dest;
	char *raw_txt;
	char **raw_tab;
	/*byte converted;*/
};


typedef struct _identity identity;
struct _identity
{
	char *nick;
	char *ident;
	char *host;
};


typedef struct _module_list module_list;
struct _module_list
{
	char *name;
	char *ident;
	char *description;
	char *auteur;
	char *version;
	module_list *next;
};

#ifdef WIN32
#include <windows.h>
#define delay(x) Sleep(x)
#include "share_func.c"

#else
#define delay(x) usleep(x * 1000)
#define closesocket(x) close(x)

#ifdef __cplusplus
extern "C" {
#endif

void log_module_info (const char *merr);
void log_module_infof (const char *s, ...);
void clean_txt (char *txt);
int cmpstar (const char *ref, const char *star);
char *strf (const char *s, ...);
char *argu_to_string (char **argu, int nbarg, const char *radical, int depart);
char **string_to_argu (const char *str, char token, int allow_empty, int *nbelement); 	/* depuis 1.7 */
int identify_mask (identity * i, const char *m);
void free_identity (identity *a);
char *str_replace (const char *data, const char *old_str, const char *new_str);
char *str_suppr (const char *buffer, const char *del);
char *multi_str_replace (const char *data, ...);
char *multi_str_suppr (const char *data, ...);
char *strpndup (const char *ptr_debut, const char *ptr_fin, int max); /* depuis 1.7 */

	
void bot_set_ident_module (const char *n);
void bot_set_auteur_module (const char *n);
void bot_set_desc_module (const char *n);
void bot_set_version_module (const char *n);
void bot_send_privmsg (const char *dest, const char *str);
void bot_send_notice (const char *dest, const char *str);
void bot_send_raw (const char *str);
void bot_send_privmsgf (const char *dest, const char *s, ...);
void bot_send_noticef (const char *dest, const char *s, ...);
void bot_send_actionf (const char *dest, const char *s, ...);   /* depuis 1.6.5 */
void bot_send_action (const char *dest, const char *str);	/* depuis 1.6.5 */
void bot_send_rawf (const char *s, ...);
ns_handler_t bot_add_cmd_handler (const char *n, const char *fct);
int bot_rm_cmd_handler (const char *n);				/* depuis 1.6 */
ns_handler_t bot_add_type_handler (const char *n, const char *fct);
int bot_rm_type_handler (const char *n);			/* depuis 1.6 */
int bot_rm_handler (ns_handler_t hd);				/* depuis 1.7 */
ns_timeout_t bot_add_timeout_handler (int t, const char *fct);
ns_timeout_t bot_add_timeout_with_param_handler (int t, const char *fct, void *param_p, unsigned int size_p);
void bot_unprotect_time_module (void);
void bot_protect_time_module (void);
void bot_set_handler_data (ns_handler_t handler, void *data); 	/* depuis 1.6 */
void *bot_get_handler_data (void); 				/* depuis 1.6 */
ns_handler_t bot_get_my_handle (void);			/* depuis 1.7 */
int bot_rm_timeout_handler (ns_timeout_t handler);		/* depuis 1.6.2 */
ns_handler_t bot_add_notice_hook (const char *fct);	/* depuis 1.6.2 */
ns_handler_t bot_add_privmsg_hook (const char *fct);	/* depuis 1.6.2 */
ns_handler_t bot_add_type_hook (const char *n, const char *fct);	/* depuis 1.6.2 */
ns_fd_t bot_add_fd_handler (int fd, int mode, const char *callback, void *arg); /* depuis 1.7 */
int bot_rm_fd (int fd, int mode); /* depuis 1.7 */
int bot_rm_fd_handler (ns_fd_t fd_hd); /* depuis 1.7 */


int bot_unload_module (const char *n);
int bot_load_module (const char *n);
int bot_load_module_cmd (const char *cmd);
int bot_unload_module_cmd (const char *cmd);
void bot_actualise_ping (void);
unsigned int bot_get_time_up (void);
unsigned int bot_get_time_online (void);	/* depuis 1.7 */
char *bot_get_kernel_version (void);
void module_loader_add_link (const char *n, void *ad);
void module_loader_rm_link (const char *n);
conf_bot *bot_conf_get_addr (void);
module_list *bot_get_module_list (void);
void bot_free_module_list (module_list * ml);
char *bot_get_info_from_conf (const char *base, unsigned int occur);
int bot_update_info_from_conf (const char *base, const char *value, const char *new_value, unsigned int mode); /* depuis 1.7 */

char **bot_get_userlist (const char *chan);
char **bot_get_chanlist (const char *user);
char *bot_get_mask (const char *user);

int is_botnick (const char *n);
int is_on_chan (const char *chan, const char *nick); 		/* depuis 1.6 */

#ifdef __cplusplus
}
#endif

#endif

#endif
